/* 
 * Plus One
 */

#include "../../func.h"

vector<int> plusOne(vector<int> &digits)
{
    add(digits, 1);
    return digits;
}

void add(vector<int> &digits, int digit)
{
    int c = digit;
    /*
    for_each(digits.rbegin(), digits.rend(), [&c](int &d){
        d += c;
        c = d/ 10;
        d %= 10;
    });
    */

    for (auto it = digits.rbegin(); it != digits.rend(); ++it)
    {
        *it += c;
        c = *it / 10;
        *it %= 10;
    }

    if (c > 0)
        digits.insert(digits.begin(), 1);
}